<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        input {
            width: 250px;
            height: 30px;
            border: 1px solid black;
        }

        div {
            position: relative;
            width: 250px;
            height: 150px;
            background-color: rgba(0, 225, 255, 0.259);
            margin-top: 20px;
            border: 1px solid skyblue;
            border-radius: 5px;
            box-sizing: border-box;
        }
        div ul{
            margin-top: 10px;
        }
        div ul li {
            list-style: none;
            line-height: 22px;
            font-size: 12px;
        }
        .lis{
            color: rgb(135, 190, 235);
        }
        span{
            position: absolute;
            width: 20px;
            height: 20px;
            margin-left: -20px;
            background-image:url(./images/cha.png);
            background-size: 20px 20px;
        }
    </style>
</head>

<body>
    <input type="search">
    <div>
        <ul>
            <li><span></span>至少有一个大写字母</li>
            <li><span></span>至少有一个小写字母</li>
            <li><span></span>至少有一个数字</li>
            <li><span></span>至少有一个特殊字符</li>
            <li><span></span>不能以空白符开头</li>
            <li><span></span>密码长度8-12之间</li>
        </ul>
    </div>
    <script>
        var input=document.querySelector("input");
        var lis=document.querySelectorAll("li");
        var spans=document.querySelectorAll("span");
        var regs=[/[A-Z]/,/[a-z]/,/\d/,/[.@$!%*#_~?&^]/,/^\S/,/^[\d\D]{8,12}$/]
        input.addEventListener('input',function(){
            var val=input.value;
            for(var i=0;i<regs.length;i++){
                var reg=regs[i];
                if(reg.test(val)){
                    lis[i].classList.add("lis");
                    spans[i].style.backgroundImage="url(./images/gou.png)"
                }
                else{
                    lis[i].classList.remove("lis");
                    spans[i].style.backgroundImage="url(./images/cha.png)"
                }
            }
        })
    </script>
</body>

</html>